
//滚动条插件
function nscroll(obj,color,width){
    // if(!obj){
    //     console.log('nscroll(obj,color,width)obj 为空')
    // }
    // if(!color){
    //     console.log('nscroll(obj,color,width)滚动条颜色为空')
    // }
    // if(!width){
    //     console.log('nscroll(obj,color,width)滚动条宽度为空')
    // }
    $(obj).niceScroll({
        touchbehavior:true,
        cursorcolor:color,
        cursoropacitymax:1,
        hwacceleration:true, 
        scrollspeed: 100,
        mousescrollstep: 80,
        sensitiverail:true,
        hidecursordelay:1000,
        bouncescroll:true,
        cursorwidth:width+'px',
        cursorborder:"0",
        cursorborderradius:"5px",
        spacebarenabled:true,
        zindex:'999999999999'
    });
}
//时间选择插件
function chooseTime(obj){
	$(obj).mobiscroll().date({
        theme: "mobiscroll-dark",
        mode: "scroller",
        display: "modal",
        lang: "zh",
        dateFormat: 'yy-mm-dd', 
        dateOrder: 'yymmdd',
        endYear: (new Date()).getFullYear(),
        maxDate: new Date(),
        defaultValue: new Date($(obj).val())
    });
}
function chooseTime2(obj){
    $(obj).mobiscroll().date({
        theme: "mobiscroll-dark",
        mode: "scroller",
        display: "modal",
        lang: "zh",
        dateFormat: 'yy-mm-dd', 
        dateOrder: 'yymmdd',
        startYear: (new Date()).getFullYear(),
        defaultValue: new Date($(obj).val())
    });
}
function chooseDateTime(obj){
    $(obj).mobiscroll().datetime({
        // preset : 'datetime',
        theme: "mobiscroll-dark",
        mode: "scroller",
        display: "modal",
        lang: "zh",
        dateFormat: 'yy-mm-dd ', 
        dateOrder: 'yymmdd',
        minDate: new Date(2017,5,5,0,00),
        defaultValue: new Date($(obj).val()),
        stepMinute: 10
    });
}
//时间格式化
function getNowFormatDate(now) {
    if (now) {
        var date = new Date(now);
    }else{
         var date = new Date();
     }       
        var seperator1 = "-";
        var seperator2 = ":";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        var strHours = date.getHours();
        var strMinutes = date.getMinutes();
        var strSeconds = date.getSeconds();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        if(strHours < 10){
            strHours = "0" + strHours;
        }
        if(strMinutes < 10){
            strMinutes = "0" + strMinutes;
        }
        if(strSeconds < 10){
            strSeconds = "0" + strSeconds;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate
                + " " + strHours + seperator2 + strMinutes
                + seperator2 + strSeconds;
        return currentdate;
    }

//中间input 时间
function dayChoosed(value){
    if(value){
        var date = new Date(value);
    }else{
        var date = new Date();
    }       
    var day = date.getDate();
    if (day < 10) {
        day = '0'+ day;
    }
    var month = date.getMonth() + 1;
    if (month < 10) {
        month = '0' + month;
    }
    var day_choosed = date.getFullYear() + '-' + month + '-' + day;
    $('#time-choosed').val(day_choosed);
}
//中间input 时间前进,后退
function dayChange(type,value){
    var now = new Date().getTime();
    var date = new Date(value).getTime();
    if (type == 'forward' && date < (now - 86400*1000)) {
        date  = new Date(value).getTime() + 24*60*60*1000
    }else if(type == 'backward' && date < now){
        date = new Date(value).getTime() - 24*60*60*1000
    }
    dayChoosed(date)
    chooseTime('#time-choosed')
}
//右侧商品显示
function goodsShow(pic,name,id){
    $('.goods-show img').attr('data-original',pic);
    $('.goods-show a').attr('href','http://www.baidu.com/'+id);
    $("img.lazy").lazyload();
    $('.goods-show h1').text(name);
    $('.goods-show').show();
}

//加载
function loading (bgColor,spinner,img) {
    $(".fakeloader").fakeLoader({
        timeToHide:9999999999999999,
        bgColor:bgColor,
        spinner:spinner,
        // imagePath:"../lib/images/google.png"
    });
}
//加载完成
function loading_success (bgColor,spinner,img) {
    $(".fakeloader").fakeLoader({
        timeToHide:0,
        bgColor:bgColor,
        spinner:spinner,
        // imagePath:"../lib/images/google.png"
    });
}
function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}

$(window).on('scroll',function(){
    var scrollTop = $(document).scrollTop();
    if (scrollTop >= 300) {
        $('.scrollTop').show()
    }else{
        $('.scrollTop').hide()
    }
})

$(document).on('click','.scrollTop',function(){
    $('html,body').animate({scrollTop: '0px'},500);
})


function imgLazyLoad(){
    $(".scrollLoading").lazyload({
        placeholder : "https://img.alicdn.com/imgextra/i1/1072286858/TB2ke6ortBopuFjSZPcXXc9EpXa_!!1072286858.png",
        effect: "fadeIn"
    });
}